﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json.Linq;
using Sparklings.JsonUtils;
using Sparklings.RayTracing;

namespace Sparklings.LevelElements
{
    public class FilterTile : EmptyTile
    {
        public FilterTile(Level l, int x, int y, RayColor color)
            :base(l,x,y)
        {
            Color = color;
        }

        public override void LoadGraphicsRelatedElements()
        {
            base.LoadGraphicsRelatedElements();
            textureColor = Level.ContentManager.Load<Texture2D>("filter_color");
        }

        public override void DrawBase(Rendering.RenderContext rc)
        {
            base.DrawBase(rc);
            rc.Draw(textureColor, Center, Color.ToColor());
        }
        public override JToken GetJsonData(JsonOverrider converter)
        {
            var ret = base.GetJsonData(converter);
            ret["filtercolor"] = converter.Write(Color);
            return ret;
        }

        public static new object ConstructFromData(JsonOverrider converter, JToken toConvert, Level level, int x, int y)
        {
            return new FilterTile(level, x, y, converter.Read<RayColor>(toConvert["filtercolor"]));
        }

        private Texture2D textureColor;
        public RayColor Color { get; set; }
    }
}
